<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<%@ page import="cn.com.dhcc.ddi.task.service.transform.FunctionAction" %>
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.fontAwesome.css" />
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.bootstrap.css" />
<script src="${ctx}/static/js/lib/dataTables/jquery.dataTables.min.js"></script>
<script src="${ctx}/static/js/lib/dataTables/dataTables.bootstrap.js"></script>
<script type="text/javascript">
$(function(){
	loadFxInfo();
	loadDataTable();
});

/**
 * 使用分页
 */
function loadDataTable(){
	$('#sample-table-1').dataTable({
	    language: {
	        "sProcessing": "处理中...",
	        "sLengthMenu": "显示 _MENU_ 项结果",
	        "sZeroRecords": "没有匹配结果",
	        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
	        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
	        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
	        "sInfoPostFix": "",
	        "sSearch": "搜索:",
	        "sUrl": "",
	        "sEmptyTable": "暂无信息",
	        "sLoadingRecords": "载入中...",
	        "sInfoThousands": ",",
	        "oPaginate": {
	            "sFirst": "首页",
	            "sPrevious": "上页",
	            "sNext": "下页",
	            "sLast": "末页"
	        } ,
	        "oAria": {
	            "sSortAscending": ": 以升序排列此列",
	            "sSortDescending": ": 以降序排列此列"
	        } 
	    },
	    "pagingType": "simple_numbers",
	    "lengthMenu": [ [ 5, 10, 25, 50, 75, 100, -1 ], [ 5, 10, 25, 50, 75, 100, "所有" ] ],
	    "displayLength": 5 ,
	    "ordering": false
	});
   $('#sample-table-1').addClass('datatable');
  $('#selectIds').addClass('center'); 
}

/**
 * 加载函数信息
 */
function loadFxInfo(){
	var setCurrentDate = '<%=FunctionAction.SET_CURRENTDATE%>'; 
	var list = [];
	list = eval(${_data});
	var context = "";
   for(var i=0; i<list.length; i++){
    	var vo = list[i];
    	var id = vo.id;
    	var fxNameCn = vo.fxNameCn;
    	var a = 1;
    	var fxType = "";
    	if(vo.fxType == "1"){
    		fxType = '${app:ctname("FX_TYPE","1")}';
    	}
    	if(vo.fxType == "2"){
    		fxType = '${app:ctname("FX_TYPE","2")}';
    	}
    	if(vo.fxType == "3"){
    		fxType = '${app:ctname("FX_TYPE","3")}';
    	}
    	if(vo.fxType == "4"){
    		fxType = '${app:ctname("FX_TYPE","4")}';
    	}
    	if(vo.fxType == "5"){
    		fxType = '${app:ctname("FX_TYPE","5")}';
    	}
    	if(vo.fxType == "6"){
    		fxType = '${app:ctname("FX_TYPE","6")}';
    	}
    	if(vo.fxType == "7"){
    		fxType = '${app:ctname("FX_TYPE","7")}';
    	}
    	if(vo.fxType != "7" || (vo.fxType == "7" && vo.fxNameEn != setCurrentDate)){
        	if(i == 0){
       			context += '<tr class="nosort">'
       			          +'<td class="profile-user-info profile-user-info-striped">'
       					  +'<div class="profile-info-row">'
    			          +'  <div class="profile-info-name" id="profile_name">'+fxType+'</div>'
    			          +'		<div class="profile-info-value" id="profile_value">'
    				      +'		<span class="editable">&nbsp;</span>'
    			          +'	 </div>'
    		              +'</div>'
    		              +'</td>'
    		              +'</tr>';
        	}else if(i != 0 && vo.fxType != list[i-1].fxType){
        		context += '<tr class="nosort">'
    			          +'<td class="profile-user-info profile-user-info-striped">'
        			  +'<div class="profile-info-row">'
    		          +'  <div class="profile-info-name" id="profile_name">'+fxType+'</div>'
    		          +'		<div class="profile-info-value" id="profile_value">'
    			      +'		<span class="editable">&nbsp;</span>'
    		          +'	 </div>'
    	              +'</div>'
    	              +'</td>'
    	              +'</tr>';
        	}
        	var fxEffectStr = "";
        	if(vo.fxDesc != null && vo.fxDesc != "" && vo.fxDesc != "undefined"){
        		fxEffectStr = $.parseJSON(eval(JSON.stringify(vo.fxDesc))).fxEffect;
        	}
        	context += '<tr class="nosort">'
    	          	 +'<td class="profile-user-info profile-user-info-striped">'
        			 +'<div class="profile-info-row">'
    		         +'  <div class="profile-info-name" id="profile_name"><input type="radio" fxNameEn="'+vo.fxNameEn+'" fxNameCn="'+vo.fxNameCn+'" '
    		         +"     argContent='"+vo.argContent+"' fxType='"+vo.fxType+"' fxDesc='"+vo.fxDesc+"' fxId='"+id+"' iscommon='"+vo.iscommon+"' onclick='changeRadio(this)'>"
    		         +'  </div>'
    		         +'		<div class="profile-info-value" id="profile_value">'
    			     +'		<span class="editable">'+fxNameCn+'（'+fxEffectStr+'）&nbsp;</span>'
    		         +'	 </div>'
    	             +'</div>'
    	             +'</td>'
    	              +'</tr>';
    	}
    } 
    $("#fxInfo table tbody").html(context);
}

var tabColMap = {};

/**
 * 选择单选按钮(即选择不同的函数)
 */
function changeRadio(val){
	var context = "";
	var vrColListHtml = "";
	if(val.checked){
		var fxNameEn = $(val).attr("fxNameEn");
		var fxNameCn = $(val).attr("fxNameCn");
		var argContent = $.parseJSON($(val).attr("argContent"));
		var fxType = $(val).attr("fxType");
		var fxIdStr = $(val).attr("fxId");
		var iscommon = $(val).attr("iscommon");
		var fx_ = '<div class="profile-info-row">'
			     +'    <div class="profile-info-name">已选择规则</div>'
			     +'    <div class="profile-info-value">'
			     +'        <input type="text" id="fxNameEnStr" hidden value="'+fxNameEn+'">'
			     +'        <input type="text" id="argContentLength" hidden value="'+argContent.length+'">'
			     +'        <input type="text" id="fxIdStr" hidden value="'+fxIdStr+'">'
			     +'        <input type="text" id="fxTypeStr" hidden value="'+fxType+'">'
			     +'        <input type="text" id="iscommonStr" hidden value="'+iscommon+'">'
				 +'        <span class="editable">'+fxNameCn+'&nbsp;'
				 +				'<span class="dropdown-hover dropup">'
				 +'          <i class="icon-question-sign position-relative dropdown-hover" style="font-size: 18px;color:gray;"></i>'
				 +					'<div class="dropdown-menu" id="detailedFxInfoUl" style="width:400px;background-color: #f9f9f9;font-size: 12px;">'
				 +                detailedFxInfo(val)
				 +					'</div>'
				 +				'</span>'
				 +'        </span>'
			     +'    </div>'
		         +'</div>';
		         
		var param_1 = "";  
        
		var mappingType = window.content.$('input[name="mappingType"]:checked').val(); 
		if(mappingType == '1'){
			var tableInfoList = ${tableInfoList}; 
			var tbInfoStr = "";
			var tbColStr = "";
	        for(var j=0; j<tableInfoList.length; j++){
	         	tbInfoStr += '<option value="'+tableInfoList[j].tableName+'">'+tableInfoList[j].tableName+'</option>';
	         	var tbColList = tableInfoList[j].tableColVos;
	         	for(var col=0; col<tbColList.length; col++){
	         		tabColMap[tableInfoList[j].tableName] = tbColList;//设置map的key 和 value
	         	}
	        }
	       	for(var j=0; j<argContent.length; j++){
				var paramDesc = argContent[j].paramDesc;
				var verifyMsg = argContent[j].verifyMsg;
				var verifyItem = argContent[j].verifyItem;
				var verityStr = "";
				if(verifyItem!= "" && verifyItem.includes('require')){
					verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'" require="true"';
				}else{
					verityStr = 'msg="'+verifyMsg+'"';
				}
				
				var argName = "arg"+(j+1);
				if(j == 0){
					var selStr = "";
					if(iscommon == "0"){//非普通函数
						if(fxType == "1" ||  (fxType == "2" || fxType == "3")){
							selStr='<select name="tableObject" id="'+argName+'" class="selectpicker col-xs-10 col-sm-6" multiple data-live-search="true" '+verityStr+'>';
							param_1 +=  '<div class="profile-info-row" style="height: 48px;" >'
							     +'    <div class="profile-info-name" style="padding-top: 12px;">'+paramDesc+'</div>'
							     +'    <div class="profile-info-value">'
								 +'        <span class="editable">'
								 +            selStr
								 +            tbInfoStr
								 +'         </select>'
								 +'       &nbsp;</span>'
							     +'    </div>'
						         +'</div>';
						}
						if(fxType == "4" || fxType == "5"){
							var removeCol = '<%=FunctionAction.REMOVE_COL%>';
							if(fxType == "5" && fxNameEn == removeCol){
								selStr='<select name="tableObject" id="'+argName+'" class="selectpicker col-xs-10 col-sm-6" multiple data-live-search="true" '+verityStr+' onchange="changeTableInfo(this)">';
								param_1 +=  '<div class="profile-info-row" style="height: 48px;" >'
								     +'    <div class="profile-info-name" style="padding-top: 12px;">'+paramDesc+'</div>'
								     +'    <div class="profile-info-value">'
									 +'        <span class="editable">'
									 +            selStr
									 +            tbInfoStr
									 +'         </select>'
									 +'       &nbsp;</span>'
								     +'    </div>'
							         +'</div>';
							}else{
								selStr='<select class="col-xs-10 col-sm-6" name="tableObject" id="'+argName+'" onchange="changeTableInfo(this)" '+verityStr+'>';
								param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
								     +'    <div class="profile-info-name">'+paramDesc+'</div>'
								     +'    <div class="profile-info-value" style="vertical-align: middle;">'
									 +'        <span class="editable">'
						           	 +           selStr
									 +'           <option value="">请选择</option>'	
									 +             tbInfoStr
									 +'         </select>'
									 +'       &nbsp;</span>'
								     +'    </div>'
							         +'</div>';
							}
						}
					}else{
						if(fxType == "2" || fxType == "3"){
							selStr='<select class="col-xs-10 col-sm-6" name="tableObject" id="'+argName+'" '+verityStr+'>';
						}else{
							selStr='<select class="col-xs-10 col-sm-6" name="tableObject" id="'+argName+'" onchange="changeTableInfo(this)" '+verityStr+'>';
						}
						param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
						     +'    <div class="profile-info-name">'+paramDesc+'</div>'
						     +'    <div class="profile-info-value" style="vertical-align: middle;">'
							 +'        <span class="editable">'
				           	 +           selStr
							 +'           <option value="">请选择</option>'	
							 +             tbInfoStr
							 +'         </select>'
							 +'       &nbsp;</span>'
						     +'    </div>'
					         +'</div>';
					}
				}			 
				if((fxType == "4" ||fxType == "5") || fxType == "6"){
					if(j == 1){//字段列
						if(iscommon == "0" && (fxType == "4" ||fxType == "5")){//非普通函数
							var fxNameEnStr = '<%=FunctionAction.ADD_COL%>';//添加虚拟字段
						     if(fxNameEn == fxNameEnStr){
						    	 vrColListHtml=  '<div class="profile-info-row" style="height: 40px;">'
								     +'    <div class="profile-info-name">'+paramDesc+'</div>'
								     +'    <div class="profile-info-value">'
									 +'        <span class="editable">'
									 +'        <input type="text" id="tabColMap" hidden value='+JSON.stringify(tabColMap)+'>'
									 +'         <select class="col-xs-10 col-sm-6" name="colList" id="'+argName+'" onchange="" '+verityStr+'>'
									 +'          <option value="">请选择字段</option>'
									 +              tbColStr
									 +'         </select>'
									 +'&nbsp;</span>'
								     +'    </div>'
							         +'</div>';
						     }else{
						    	 param_1 +=  '<div class="profile-info-row" style="height: 48px;">'
								     +'    <div class="profile-info-name" style="padding-top: 12px;">'+paramDesc+'</div>'
								     +'    <div class="profile-info-value">'
									 +'        <span class="editable">'
									 +'        <input type="text" id="tabColMap" hidden value='+JSON.stringify(tabColMap)+'>'
									 +'         <select class="selectpicker col-xs-10 col-sm-6" name="colList" id="'+argName+'" multiple data-live-search="true" '+verityStr+'>'
									 +              tbColStr
									 +'         </select>'
									 +'&nbsp;</span>'
								     +'    </div>'
							         +'</div>';
						     }  
						}else{
							param_1 +='<div class="profile-info-row" style="height: 40px;">'
								     +'    <div class="profile-info-name">'+paramDesc+'</div>'
								     +'    <div class="profile-info-value">'
									 +'        <span class="editable">'
									 +'        <input type="text" id="tabColMap" hidden value='+JSON.stringify(tabColMap)+'>'
									 +'         <select class="col-xs-10 col-sm-6" name="colList" id="'+argName+'" onchange="" '+verityStr+'>'
									 +'          <option value="">请选择字段</option>'
									 +              tbColStr
									 +'         </select>'
									 +'&nbsp;</span>'
								     +'    </div>'
							         +'</div>';
						}
					}
				}
				if(((fxType == "2"||fxType == "3") && j > 0)||(((fxType == "4"||fxType == "5") || fxType == "6")&&j > 1)){
					 param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
	  				     +'    <div class="profile-info-name">'+paramDesc+'</div>'
	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	  					 +'        <span class="editable"><input class="col-xs-10 col-sm-6" type="text" name="colName" id="'+argName+'" '+verityStr+'/>&nbsp;</span>'
	  				     +'    </div>'
	  			         +'</div>';
				}
			} 
		}
		if(mappingType == '2'){
			
		}
		if(mappingType == '3'){
			for(var j=0; j<argContent.length; j++){
				var paramDesc = argContent[j].paramDesc;
				var verifyMsg = argContent[j].verifyMsg;
				var verifyItem = argContent[j].verifyItem;
				var verityStr = "";
				if(verifyItem!= "" && verifyItem.includes('require')){
					verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'" require="true"';
				}else{
					verityStr = 'msg="'+verifyMsg+'"';
				}				
				var argName = "arg"+(j+1);
				var addPrefixToFileName = '<%=FunctionAction.ADD_PREFIX_TO_FILE_NAME%>';
				var addSuffixToFileName = '<%=FunctionAction.ADD_SUFFIX_TO_FILE_NAME%>';
				if(j == 0 && (fxNameEn == addPrefixToFileName || fxNameEn == addSuffixToFileName)){
					var fileAddStr ='<input type="radio" name="fileAddMethod" value="0" checked onclick="changeFileAddMethod(this)">'
							         +'     <span>自定义</span>&nbsp;&nbsp;'
							         +'<input style="margin-left:15px;" type="radio" name="fileAddMethod" value="1" onclick="changeFileAddMethod(this)">'
							         +' <span>添加默认值</span>&nbsp;&nbsp;'
							         +' </button>';
			        param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
	  				     +'    <div class="profile-info-name">'+paramDesc+'</div>'
	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	  					 +'        <span class="editable">'+fileAddStr+'&nbsp;</span>'
	  				     +'    </div>'
	  			         +'</div>'; 
  			      var fxBtn ='<button id="fileAddFxBtn" type="button" class="btn btn-success btn-xs" onclick="fileAddFx()" style="display: none;">'
	   					+ '<i class="icon-plus-sign icon-on-right"></i> 选择函数&nbsp;&nbsp;'
		                + '</button>'  
		                +'<input id="chooseFxVerify" type="text" style="display: none;" msg="请选择函数" require="true">';	 		               
 			        param_1 +=  '<div class="profile-info-row" style="height: 40px;display:none;" id="fileAddFx">'
	  				     +'    <div class="profile-info-name">选择函数</div>'
	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	  					 +'        <span class="editable">'+fxBtn+'&nbsp;'
	  					 +'          <span class="mg-left12" style="display: none;">已选函数：<span id="choosedFx" ></span></span>&nbsp;'
	                     +'          <span id="vrDetailInfo" style="display: none;"></span>'
	  					 +'        </span>'
	  				     +'    </div>'
	  			         +'</div>'; 
 			        param_1 +=  '<div class="profile-info-row" style="height: 40px;display:none;" id="dateFormatID">'
	  				     +'    <div class="profile-info-name">日期格式</div>'
	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	  					 +'        <span class="editable">'
	  					 +'         <select id="dateFormat" msg="请选择日期格式" require="true">'
	  					 +'           <option value="">请选择</option>'
	  					 +'           <option>yyyy-MM-dd</option>'
	  					 +'           <option>yyyy/MM/dd</option>'
	  					 +'           <option>yyyyMMdd</option>'
	  					 +'           <option>yyyy-MM-dd HH:mm:ss</option>'
	  					 +'           <option>yyyy/MM/dd HH:mm:ss</option>'
	  					 +'           <option>yyyyMMdd HH:mm:ss</option>'
	  					 +'         </select>'
	  					 +'        </span>'
	  				     +'    </div>'
	  			         +'</div>';           

				}
				if(j != 0 && (fxNameEn == addPrefixToFileName || fxNameEn == addSuffixToFileName) 
						|| (fxNameEn != addPrefixToFileName && fxNameEn != addSuffixToFileName)){
					param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
					     +'    <div class="profile-info-name">'+paramDesc+'</div>'
					     +'    <div class="profile-info-value" style="vertical-align: middle;">'
						 +'        <span class="editable"><input class="col-xs-10 col-sm-6" type="text" name="colName" id="'+argName+'" '+verityStr+'/>&nbsp;</span>'
					     +'    </div>'
				         +'</div>';
				}
			}		         
		}

        //detailedFxInfo(val);//函数详细信息
	}
	context = fx_ + param_1;
	$("#mapping_rule").html(context);
	verifyHandle();//校验处理
	activateSelect(iscommon,fxType,fxNameEn); //激活select
	$('#dataMappingChooseModal').modal('hide');
	addVrColMappingRule(val,tbInfoStr,tbColStr);
	

	
}

/**
 * 添加虚拟字段
 */
function addVrColMappingRule(val,tbInfoStr,tbColStr){
	var context = "";
	var vrColListHtml = "";
	if(val.checked){
		var fxNameEn = $(val).attr("fxNameEn");
		var fxNameCn = $(val).attr("fxNameCn");
		var argContent = $.parseJSON($(val).attr("argContent"));
		var fxType = $(val).attr("fxType");
		var fxIdStr = $(val).attr("fxId");
		var iscommon = $(val).attr("iscommon");
		var lastStr = "";
		var fxNameEnStr = '<%=FunctionAction.ADD_COL%>';//添加虚拟字段
	    if(fxNameEn == fxNameEnStr){
	    	var fx_ = '<div class="profile-info-row">'
			     +'    <div class="profile-info-name">已选择规则</div>'
			     +'    <div class="profile-info-value">'
			     +'        <input type="text" id="fxNameEnStr" hidden value="'+fxNameEn+'">'
			     +'        <input type="text" id="argContentLength" hidden value="'+argContent.length+'">'
			     +'        <input type="text" id="fxIdStr" hidden value="'+fxIdStr+'">'
			     +'        <input type="text" id="fxTypeStr" hidden value="'+fxType+'">'
			     +'        <input type="text" id="iscommonStr" hidden value="'+iscommon+'">'
				 +'        <span class="editable">'+fxNameCn+'&nbsp;'
				 +				'<span class="dropdown-hover dropup">'
				 +'          <i class="icon-question-sign position-relative dropdown-hover" style="font-size: 18px;color:gray;"></i>'
				 +					'<div class="dropdown-menu" id="detailedFxInfoUl" style="width:400px;background-color: #f9f9f9;font-size: 12px;">'
				 +                detailedFxInfo(val)
				 +					'</div>'
				 +				'</span>'
				 +'        </span>'
			     +'    </div>'
		         +'</div>';
		         
			var param_1 = "";  
	      	for(var j=0; j<argContent.length; j++){
				var paramDesc = argContent[j].paramDesc;
				var verifyMsg = argContent[j].verifyMsg;
				var verifyItem = argContent[j].verifyItem;
				var verityStr = "";
				if(verifyItem!= "" && verifyItem.includes('require')){
					verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'" require="true"';
				}else{
					verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'"';
				}
				
				var argName = "arg"+(j+1);
				if(j == 0){
					var selStr = "";
					selStr='<select class="col-xs-10 col-sm-6" name="tableObject" id="'+argName+'" onchange="changeTableInfo(this)" '+verityStr+'>';
					param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
					     +'    <div class="profile-info-name">'+paramDesc+'</div>'
					     +'    <div class="profile-info-value" style="vertical-align: middle;">'
						 +'        <span class="editable">'
			           	 +           selStr
						 +'           <option value="">请选择</option>'	
						 +             tbInfoStr
						 +'         </select>'
						 +'       &nbsp;</span>'
					     +'    </div>'
				         +'</div>';
				}			 
				if(j > 0 && j != argContent.length - 1){
	 			     if(j == 2){
	 			    	var str = '<input type="radio" name="vrMethod" value="0" checked onclick="changeVrMethod(this)">'
	 				         +'     <span>设置值</span>&nbsp;&nbsp;'
	 				         +'<input style="margin-left:15px;" type="radio" name="vrMethod" value="1" onclick="changeVrMethod(this)">'
	 				         +' <span>字段值计算</span>&nbsp;&nbsp;'
	 				         +' </button>'
				        param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
	 	  				     +'    <div class="profile-info-name">'+paramDesc+'</div>'
	 	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	 	  					 +'        <span class="editable">'+str+'&nbsp;</span>'
	 	  				     +'    </div>'
	 	  			         +'</div>';   
 	  			      var fxBtn ='<button type="button" class="btn btn-success btn-xs" onclick="vrRuleAddFx()" >'
			   					+ '<i class="icon-plus-sign icon-on-right"></i> 选择函数&nbsp;&nbsp;'
	 			                + '</button>'  
	 			                +'<input id="chooseFxVerify" type="text" style="display: none;" datatype="require" msg="请选择函数" require="true">';	 		               
 	  			        param_1 +=  '<div class="profile-info-row" style="height: 40px;" id="vrRuleAddFx">'
	 	  				     +'    <div class="profile-info-name">选择函数</div>'
	 	  				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	 	  					 +'        <span class="editable">'+fxBtn+'&nbsp;'
	 	  					 +'          <span class="mg-left12" style="display: none;">已选函数：<span id="choosedFx" ></span></span>&nbsp;'
	 	                     +'          <span id="vrDetailInfo" style="display: none;"></span>'
	 	  					 +'        </span>'
	 	  				     +'    </div>'
	 	  			         +'</div>';        

	 			     }else{
	 			    	param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
	 	 				     +'    <div class="profile-info-name">'+paramDesc+'</div>'
	 	 				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
	 	 					 +'        <span class="editable"><input class="col-xs-10 col-sm-6" type="text" name="colName" id="'+argName+'" '+verityStr+'/>&nbsp;</span>'
	 	 				     +'    </div>'
	 	 			         +'</div>';
	 			     }    
				}
				if(j == argContent.length - 1){
					lastStr +='<div id="colItem" class="profile-info-row"></div>';         
					/* lastStr += '<div class="profile-info-row" style="height: 40px;" id="vrRule">'
						     +'    <div class="profile-info-name">'+paramDesc+'</div>'
						     +'    <div class="profile-info-value" style="vertical-align: middle;">'
							 +'        <span class="editable"><input class="col-xs-10 col-sm-6" type="text" name="colName" id="arg4" '+verityStr+'/>&nbsp;</span>'
						     +'    </div>'
					         +'</div>'; */
		         	
				}
			} 
	      	var col  =  '<div class="profile-info-row" style="height: 40px;display:none;" id="vrColList">'
				     +'    <div class="profile-info-name" style="padding-top: 12px;">作用字段</div>'
				     +'    <div class="profile-info-value">'
					 +'        <span class="editable">'
					 +'        <input type="text" id="tabColMap" hidden value='+JSON.stringify(tabColMap)+'>'
					 +'         <select class="col-xs-10 col-sm-6" name="colList" id="arg3" '+verityStr+'>'
					 +'          <option value="">请选择字段</option>'
					 +              tbColStr
					 +'         </select>'
					 +'&nbsp;</span>'
				     +'    </div>'
			         +'</div>';
	      	context = fx_ + param_1 + col + lastStr;
	    	$("#mapping_rule").html(context);
	    	$("#arg3").removeAttr("datatype").removeAttr("require");
	    	$("#arg4").removeAttr("datatype").removeAttr("require");
	    	//$("#saveBtn").attr("disabled","disabled");
	    	$('#dataMappingChooseModal').modal('hide');
	    	verifyHandle();//校验处理
	    }
	}
}

/**
 * 虚拟规则添加函数
 */
function vrRuleAddFx(){
	var context = "";
	var fxNameEnStr = $("#fxNameEnStr").val();
	var addCol = '<%=FunctionAction.ADD_COL%>';
	var setDefault = '<%=FunctionAction.SET_DEFAULT%>';
	var setCurrentDate = '<%=FunctionAction.SET_CURRENTDATE%>'; 
	var whenNullSetDefault = '<%=FunctionAction.WHEN_NULL_SET_DEFAULT%>';
	var vrMethod = $("input[name='vrMethod']:checked").attr("value");
	if(addCol == fxNameEnStr){
		var list = [];
		list = eval(${_data});
		var fxType = '${app:ctname("FX_TYPE","6")}';
		context += '<div class="table-responsive">'
				  +' <div class="row">'
				  +'  <div class="col-xs-12">'
			      +'   <div class="widget-main">'
				  +'    <div class="profile-user-info profile-user-info-striped">'
				  +'     <table id="sample-table-1" cellspacing="0" width="100%" style="border:0px;margin-bottom:6px;margin-top:-13px;" >'
				  +'      <thead>'
				  +'       <tr>'
			      +'        <th class="nosort" height="0px"> &nbsp;  </th>'
			      +'       </tr>'  
				  +'      </thead>'
				  +'      <tbody>';
		context += '<tr class="nosort">'
	          +'<td class="profile-user-info profile-user-info-striped">'
			  +'<div class="profile-info-row">'
	          +'  <div class="profile-info-name" id="profile_name">'+fxType+'</div>'
	          +'		<div class="profile-info-value" id="profile_value">'
		      +'		<span class="editable">&nbsp;</span>'
	          +'	 </div>'
              +'</div>'
              +'</td>'
              +'</tr>';
		for(var i=0;i<list.length;i++){
			var vo = list[i];
	    	var id = vo.id;
	    	var fxNameCn = vo.fxNameCn;
            var temp ='<tr class="nosort">'
		          	 +'<td class="profile-user-info profile-user-info-striped">'
	    			 +'<div class="profile-info-row">'
			         +'  <div class="profile-info-name" id="profile_name"><input type="radio" fxNameEn="'+vo.fxNameEn+'" fxNameCn="'+vo.fxNameCn+'" '
			         +"     argContent='"+vo.argContent+"' fxType='"+vo.fxType+"' fxDesc='"+vo.fxDesc+"' fxId='"+id+"' iscommon='"+vo.iscommon+"' onclick='chooseFx(this)'>"
			         +'  </div>'
			         +'		<div class="profile-info-value" id="profile_value">'
				     +'		<span class="editable">'+fxNameCn+'&nbsp;</span>'
			         +'	 </div>'
		             +'</div>'
		             +'</td>'
		              +'</tr>';
	    	if(vo.fxType == "6"){
	    		if(vrMethod == "0"){
	    			if(vo.fxNameEn == setDefault || vo.fxNameEn == setCurrentDate || vo.fxNameEn == whenNullSetDefault){
	    				context += temp;
	    			}else{
	    				continue;
	    			}
	    		}else{
					if(vo.fxNameEn != setDefault && vo.fxNameEn != setCurrentDate && vo.fxNameEn != whenNullSetDefault){
						context += temp;
	    			}else{
	    				continue;
	    			}
	    		}	    		
	    	}else{
	    		continue;
	    	}
			
		}
		context += '  </tbody></table></div><div></div><div></div>';
		context+='<div style="margin-bottom:6px;">&nbsp;</div>';

		 $(window.content.document.getElementById('dataMappingChooseDiv')).html(context);
		 var hiddenByClick = false;
	     window.parent.iframeModal("dataMappingChooseModal", $(window.content.document.getElementById('dataMappingChooseModal')).html(), hiddenByClick);
	     loadDataTable();
	     
	}
}

/**
 * 选择函数
 */
function chooseFx(val){
	var fxNameEn = $(val).attr("fxNameEn");
	var fxNameCn = $(val).attr("fxNameCn");
	var argContent = $.parseJSON($(val).attr("argContent"));
	var fxType = $(val).attr("fxType");
	var fxIdStr = $(val).attr("fxId");
	$("#choosedFx").parent().css("display","");
	$("#choosedFx").text(fxNameCn);
	$("#choosedFx").attr("fxId",fxIdStr);
	$("#choosedFx").attr("fxNameEn",fxNameEn);
	$("#arg4").val(fxNameCn);
	var strOperator = '<%=FunctionAction.STR_OPERATOR%>';
	var setDefault = '<%=FunctionAction.SET_DEFAULT%>';
	var whenNullSetDefault = '<%=FunctionAction.WHEN_NULL_SET_DEFAULT%>';
	var setCurrentdate = '<%=FunctionAction.SET_CURRENTDATE%>';
 	var param_1 = "";
 	if(fxNameEn == strOperator || fxNameEn == setDefault || fxNameEn == whenNullSetDefault){
 		for(var j=2; j<argContent.length; j++){
 			var paramDesc = argContent[j].paramDesc;
 			var verifyMsg = argContent[j].verifyMsg;
 			var verifyItem = argContent[j].verifyItem;
 			var verityStr = "";
 			if(verifyItem!= "" && verifyItem.includes('require')){
 				verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'" require="true"';
 			}else{
 				verityStr = 'datatype="'+verifyItem+'" msg="'+verifyMsg+'"';
 			}
 			
 			var argName = "arg"+(j+2);
 		 	param_1 +=  '<div class="profile-info-row" style="height: 40px;">'
 				     +'    <div class="profile-info-name">'+paramDesc+'</div>'
 				     +'    <div class="profile-info-value" style="vertical-align: middle;">'
 					 +'        <span class="editable"><input class="col-xs-10 col-sm-6" type="text" name="colName" id="'+argName+'" '+verityStr+'/>&nbsp;</span>'
 				     +'    </div>'
 			         +'</div>';
 		}
	}
 	
 	var vrDetailInfo ='<span class="dropdown-hover dropup">'
		             +'    <i class="icon-question-sign position-relative dropdown-hover" style="font-size: 18px;color:gray;"></i>'
					 +'  <div class="dropdown-menu" style="width:400px;background-color: #f9f9f9;font-size: 12px;">'
					 +     detailedFxInfo(val)
					 +'  </div>'
					 +'</span>'
    $("#vrDetailInfo").html(vrDetailInfo);
	$("#vrDetailInfo").css("display","");				 
	$("#colItem").html(param_1); 
	var vrFxId = $("#choosedFx").attr("fxId");
	if(vrFxId == "" || vrFxId == undefined || vrFxId == null){
		
	}else{
		$("#chooseFxVerify").attr("value",vrFxId);
		if($("#chooseFxVerify").next().hasClass("btn-error") ){
			$("#chooseFxVerify").next().remove();
		}
	}
	//文件类型设置日期格式样式
	if(fxType == "7" && fxNameEn == setCurrentdate){
		$("#dateFormatID").css("display","");
		$("#dateFormat").attr("datatype","require");
	}else{
		$("#dateFormatID").css("display","none");
		$("#dateFormat").removeAttr("datatype");
	}
	$('#dataMappingChooseModal').modal('hide');
	
}

/**
 * 改变虚拟方式
 */
function changeVrMethod(val){
	var inputV = $(val).attr("value");
	$("#chooseFxVerify").attr("value","");
	if(inputV == "0"){// 0设置默认值  1字段值计算
		$("#vrColList").css("display","none");
		$("#arg3").removeAttr("datatype");
		$("#arg3").prop("selectedIndex", 0);
		$("#vrDetailInfo").html('');
		$("#chooseFxVerify").attr("datatype","require");
	}else{
		$("#vrColList").css("display","");
		$("#arg3").attr("datatype","require");
    	$("#arg4").attr("datatype","require");
    	$("#colItem").html("");
    	$("#choosedFx").parent().css("display","none");
    	$("#arg4").val("");
    	$("#vrDetailInfo").html('');
    	$("#chooseFxVerify").removeAttr("datatype");
    	if($("#chooseFxVerify").next().hasClass("btn-error") ){
        	$("#chooseFxVerify").next().remove();
    	}
	}
}

/**
 * 函数详细信息
 */
function detailedFxInfo(val){
	var fxNameCn = $(val).attr("fxNameCn");
	var argContent = $.parseJSON($(val).attr("argContent"));
	var fxDesc =  $.parseJSON($(val).attr("fxDesc"));
	var fxEffect = fxDesc.fxEffect;
	var notFitCondition = fxDesc.notFitCondition;
	var returnDesc = fxDesc.returnDesc;
	var mappingModel = fxDesc.mappingModel;
	var example = fxDesc.example;

	var inputParam = "";
	for(var i = 0; i<argContent.length; i++){
		inputParam += "参数" + (i+1) + "：" + argContent[i].paramDesc;
		if(i<argContent.length-1){
			inputParam += "<br>";
		}
	}
	var fxInfoStr = "";
	fxInfoStr = ' <div id="detailedFxInfo">'
		 		+'	<div class="row">'
				+'		<div class="col-sm-4 text-right" >函数作用:</div>'
				+'		<div class="col-sm-8 text-left" >'
				+'			<span class="editable" id="fxEffect">'+fxEffect+'&nbsp;</span>'
				+'		</div>'
				+'	</div>'
				+'	<div class="row">'
				+'		<div class="col-sm-4 text-right">不适用情况：</div>'
				+'		<div class="col-sm-8">'
				+'			<span class="editable" id="notFitCondition">'+notFitCondition+'&nbsp;</span>'
				+'		</div>'
				+'	</div>'
				+'	<div class="row">'
				+'		<div class="col-sm-4 text-right" align="center">'
			 	+'			<span>输入：</span>'
				+'		</div>'
				+'		<div class="col-sm-8">'
				+'			<span class="editable" id="inputParam">'+inputParam+'&nbsp;</span>'
				+'	    </div>'
				+'	</div>'
				+'	<div class="row">'
				+'		<div class="col-sm-4 text-right">输出：</div>'
				+'		<div class="col-sm-8">'
				+'			<span class="editable" id="returnDesc">'+returnDesc+'&nbsp;</span>'
				+'		</div>'
				+'	</div>'
				+'	<div class="row">'
				+'		<div class="col-sm-4 text-right">映射提示模板：</div>'
				+'		<div class="col-sm-8">'
				+			'<span class="editable" id="mappingModel">'+mappingModel+'&nbsp;</span>'
				+'		</div>'
				+'	</div>'
				+'	<div class="row">'
				+'		<div class="col-sm-4 text-right">举例：</div>'
				+'		<div class="col-sm-8">'
				+'			<span class="editable" id="example">'+example+'&nbsp;</span>'
				+'		</div>'
				+'	</div>'
				+'</div>';	
	return fxInfoStr;
	
}

function selectedTable(){
	var selectVal = $("#tableObject").val();
	var textVal = $("#selectedTable").text();
	if(textVal != null && textVal.trim() != ""){
		var val = textVal +"、"+ selectVal;
		$("#selectedTable").text(val);
	}else{
		val = selectVal;
		$("#selectedTable").text(val);
	}
}

/**
 * 改变文件类型添加方式
 */
function changeFileAddMethod(val){
	var inputV = $(val).attr("value");
	$("#chooseFxVerify").attr("value","");
	if(inputV == '0'){//0自定义    1设置默认值
		$("#fileAddFxBtn").css("display","none");
		$("#fileAddFx").css("display","none");
		$("#dateFormatID").css("display","none");
		$("#dateFormat").removeAttr("datatype");
		$("#arg2").parent().parent().parent().css("display","");
		$("#arg2").attr("datatype","require");
		$("#vrDetailInfo").html('');
		$("#chooseFxVerify").removeAttr("datatype");
    	if($("#chooseFxVerify").next().hasClass("btn-error") ){
        	$("#chooseFxVerify").next().remove();
    	}		
	}else{
		$("#fileAddFxBtn").css("display","");
		$("#fileAddFx").css("display","");
		$("#arg2").parent().parent().parent().css("display","none");
		$("#arg2").removeAttr("datatype");
    	$("#vrDetailInfo").html('');
    	$("#choosedFx").removeAttr("fxId");
    	$("#choosedFx").removeAttr("fxNameEn");
    	$("#choosedFx").parent().css("display","none");
    	//$("#chooseFxVerify").attr("datatype","require"); 去掉函数验证
	}
}

/**
 * 文件类型选择函数
 */
function fileAddFx(){
	var context = "";
	var fxNameEnStr = $("#fxNameEnStr").val();
	var addPrefixToFileName = '<%=FunctionAction.ADD_PREFIX_TO_FILE_NAME%>';
	var addSuffixToFileName = '<%=FunctionAction.ADD_SUFFIX_TO_FILE_NAME%>';
	var setCurrentDate = '<%=FunctionAction.SET_CURRENTDATE%>'; 	
	var vrMethod = $("input[name='vrMethod']:checked").attr("value");
	if(fxNameEnStr == addPrefixToFileName || fxNameEnStr == addSuffixToFileName){
		var list = [];
		list = eval(${_data});
		var fxType = '${app:ctname("FX_TYPE","7")}';
		context += '<div class="table-responsive">'
				  +' <div class="row">'
				  +'  <div class="col-xs-12">'
			      +'   <div class="widget-main">'
				  +'    <div class="profile-user-info profile-user-info-striped">'
				  +'     <table id="sample-table-1" cellspacing="0" width="100%" style="border:0px;margin-bottom:6px;margin-top:-13px;" >'
				  +'      <thead>'
				  +'       <tr>'
			      +'        <th class="nosort" height="0px"> &nbsp;  </th>'
			      +'       </tr>'  
				  +'      </thead>'
				  +'      <tbody>';
		context += '<tr class="nosort">'
	          +'<td class="profile-user-info profile-user-info-striped">'
			  +'<div class="profile-info-row">'
	          +'  <div class="profile-info-name" id="profile_name">'+fxType+'</div>'
	          +'		<div class="profile-info-value" id="profile_value">'
		      +'		<span class="editable">&nbsp;</span>'
	          +'	 </div>'
              +'</div>'
              +'</td>'
              +'</tr>';
		for(var i=0;i<list.length;i++){
			var vo = list[i];
	    	var id = vo.id;
	    	var fxNameCn = vo.fxNameCn;
            var temp ='<tr class="nosort">'
		          	 +'<td class="profile-user-info profile-user-info-striped">'
	    			 +'<div class="profile-info-row">'
			         +'  <div class="profile-info-name" id="profile_name"><input type="radio" fxNameEn="'+vo.fxNameEn+'" fxNameCn="'+vo.fxNameCn+'" '
			         +"     argContent='"+vo.argContent+"' fxType='"+vo.fxType+"' fxDesc='"+vo.fxDesc+"' fxId='"+id+"' iscommon='"+vo.iscommon+"' onclick='chooseFx(this)'>"
			         +'  </div>'
			         +'		<div class="profile-info-value" id="profile_value">'
				     +'		<span class="editable">'+fxNameCn+'&nbsp;</span>'
			         +'	 </div>'
		             +'</div>'
		             +'</td>'
		              +'</tr>';
	    	if(vo.fxType == "7"){
    			if(vo.fxNameEn == setCurrentDate ){
    				context += temp;
    			}
	    	}
		}
		context += '  </tbody></table></div><div></div><div></div>';
		context+='<div style="margin-bottom:6px;">&nbsp;</div>';

		 $(window.content.document.getElementById('dataMappingChooseDiv')).html(context);
		 var hiddenByClick = false;
	     window.parent.iframeModal("dataMappingChooseModal", $(window.content.document.getElementById('dataMappingChooseModal')).html(), hiddenByClick);
	     loadDataTable();      
	}
}

</script>
<style>
#profile_name{
	text-align: center;
	width: 100px;
}
#profile_value{
	margin-left: 100px;
}
table.dataTable {
    margin-top: -13px !important;
    margin-bottom: 6px !important;
}
</style>
<div class="table-responsive">
	<div class="row">
		<div class="col-xs-12">
			<div class="widget-main">
				<div class="profile-user-info profile-user-info-striped" id="fxInfo">
				<table id="sample-table-1" cellspacing="0" width="100%" style="border:0px;" >
				 <thead>
				 <tr>
				   <th class="nosort" height="0px"> &nbsp;  </th>
                 </tr>  
				 </thead>
                 <tbody>
                 
                 </tbody>
				 	
				</table>
				
				</div>
				<!--  <div class="widget-toolbar no-border">
			        <a class="btn btn-info btn-xs" id="btnSave" onclick="btnSave()"><i class="icon-ok bigger-110"></i>保存&nbsp;&nbsp;</a>
			        <a class="btn btn-primary btn-xs" onclick="$('#dataMappingChooseModal').modal('hide');"><i class="icon-remove"></i> 取消&nbsp;&nbsp;</a>
			    </div> -->
			  
			</div>
		</div>
	</div>
</div>